﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
//using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public delegate void Click2DDelegate(GameObject go, object data);
public struct shuaiStruct
{
    public GameObject go;
    //public object data;
    public Dictionary<string, object> data;
    //public VoidDelegate onClick;
}

public class InputManager : MonoBehaviour
{
    public static InputManager Instance;



    private void Awake()
    {
        Instance = this;

    }

    void Start()
    {
        
    }

    void Update()
    {
        //Debug
        if (Input.GetKeyDown(KeyCode.T))
        {
            DebugPanel.Instance.Change();
        }


        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 0);
            if (hit.collider != null)
            {
                
                
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 0);
            if (hit.collider != null)
            {
                
            }
        }

        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("上");
            //ShuaiManager.Instance.current_element.Move(Vector2.up);
            ShuaiManager.Instance.current_element.Change();
        }

        if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("下");
            //ShuaiManager.Instance.current_element.Move(Vector2.down);

            CellFunctions.MoveDownAllCell();
        }

        //"左"
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            ShuaiManager.Instance.current_element.Move(Vector2.left);
        }
        //if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        //{
            
        //}

        //"右"
        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            ShuaiManager.Instance.current_element.Move(Vector2.right);
        }
        //if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        //{
            
        //}

        if (Input.GetKeyDown(KeyCode.Space))
        {
            //Debug.Log(123);


            List<List<int>> list = new List<List<int>>
            {
                new List<int> { 1, 2, 3},
                new List<int> { 4, 5, 6},
                new List<int> { 7, 8, 9},
            };

            foreach (var item in list)
            {
                foreach (var item1 in item)
                {
                    Debug.Log(item1);
                }
            }

            Debug.Log("------------------------");

            List<List<int>> list2 = rotate(list);

            foreach (var item in list2)
            {
                foreach (var item1 in item)
                {
                    Debug.Log(item1);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            List<List<int>> temp = new List<List<int>>();
            Debug.Log(temp);
            Debug.Log(temp[0]);
            //if (temp[0] == null)
            //{
            //    temp[0] = new List<int>();
            //}



        }

        if (Input.GetKeyDown(KeyCode.Keypad2))
        {

        }

        if (Input.GetKeyDown(KeyCode.Keypad3))
        {
            ;
        }

        if (Input.GetKeyDown(KeyCode.Keypad4))
        {
            
        }

    }

    public List<List<int>> rotate(List<List<int>> matrix)
    {
        //逆时针旋转 90 度
        //列 = 行
        //行 = n - 1 - 列(j);  n表示总行数
        //List<List<int>> temp = new List<List<int>>();

        List<List<int>> temp = new List<List<int>>
        {
            new List<int> {0,0,0},
            new List<int> {0,0,0},
            new List<int> {0,0,0},
        };


        var len = matrix.Count;


        for (var i = 0; i<len; i++)
        {
            for (var j = 0; j<len; j++)
            {
                var k = len - 1 - j;
                if (temp[k] == null)
                {
                    temp[k] = new List<int>();
                }
                temp[k][i] = matrix[i][j];
            }
        }

        return temp;
    }

}
